package com.ayq.activiti.manager.job;

import com.ayq.activiti.common.util.ConstantPool;
import com.ayq.activiti.manager.domain.applymanager.entity.ActivitiApplyManager;
import com.ayq.activiti.manager.domain.applymanager.service.IActivitiApplyManagerService;
import com.ayq.activiti.manager.service.RabbitMqTaskService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 *
 * <p>流程任务调度类</p>
 * @Author ayq
 * @Date 2021/4/14 13:45
 */
@Component
@Slf4j
public class ActivitiUpdateNodeInfoJob {
    private static Logger logger = LoggerFactory.getLogger(ActivitiUpdateNodeInfoJob.class);

    @Autowired
    private RabbitMqTaskService rabbitMqTaskService;
    @Autowired
    private IActivitiApplyManagerService iActivitiApplyManagerService;

    @XxlJob(value = "activitiUpdateNodeInfoHandler", init = "init", destroy = "destroy")
    public void demoJobHandler2() throws Exception {
        // param parse
        try {
            XxlJobHelper.log("开始流程节点信息缓存预热任务");
            QueryWrapper<ActivitiApplyManager> wrapper = new QueryWrapper<ActivitiApplyManager>();
            wrapper.in(ConstantPool.STATUS,2,3,5);
            List<ActivitiApplyManager> list = iActivitiApplyManagerService.list(wrapper);
            XxlJobHelper.log("查询审批中、驳回的流程申请信息成功");
            for (ActivitiApplyManager activitiApplyManager : list) {
                rabbitMqTaskService.updateNodeInfo(activitiApplyManager.getRuId());
            }
            XxlJobHelper.log("流程节点信息缓存预热任务成功");
        } catch (Exception e) {
            XxlJobHelper.log("开始流程节点信息缓存预热任务失败");
            XxlJobHelper.log(e);
            throw new Exception(e);
        }
    }
    public void init(){
        log.info("开始流程节点信息缓存预热任务初始化");
    }
    public void destroy(){
        log.info("开始流程节点信息缓存预热任务销毁");
    }
}
